/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2024/6/12
 * Time: 12:24
 */

#ifndef GAME_H
#define GAME_H
#include "CardDeck.h"
#include "Global.h"
#include "Player.h"

using namespace std;
namespace Upgrade {

    class Game : public QObject
    {
        Q_OBJECT
        friend class GameUi;

    public:
        explicit Game(int _playerNum, int _deckNum, int bottomNum);

        void AddPlayer(PlayerSPtr _player);

        void Upgrade(bool isMain, int rank);

        void Start();

        void PrintBottomCard();

        void SetMainSuit(const PlayerSPtr & _player, CardSuit _suit);

        PlayerSPtr GetMainPlayer();

        CardSuit GetMainSuit() const;

        CardRank GetMainRank() const;
    signals:
        // void RankChanged();// rank改变
        // void MainPlayerChanged();// 主家改变
        void IsAlready(const PlayerSPtr & _player, CardSuit _suit);// 确定主家及花色
        void TimeOut();
        void SendCard(const PlayerSPtr & _player, const CardSPtr & _card);

        void DealFinished(const PlayerSPtr & _player = nullptr);//发牌结束
        // void BeatFinished();    //压牌结束

    private:
        void InitEvent();
    private:
        CardDeckSPtr      deck_ {nullptr};
        QList<PlayerSPtr> players_;

        QMap<Player::GroupId, CardRank> player_trump_;

        QTimer * timer_ {nullptr};

        mutable QMutex mutex_;
        PlayerSPtr     main_player_ {nullptr};
        CardSuit       main_suit_ = CardSuit::Unkonw;
    };

    using GameSPtr = shared_ptr<Game>;

}// namespace Upgrade

#endif//GAME_H
